package com.zixi.beverage_order.service.customer;

import com.zixi.beverage_order.mapper.OrderListMapper;
import com.zixi.beverage_order.mapper.OrderedProductMapper;
import com.zixi.beverage_order.mapper.ProductMapper;
import com.zixi.beverage_order.pojo.OrderList;
import com.zixi.beverage_order.pojo.OrderedProduct;
import com.zixi.beverage_order.pojo.Product;
import com.zixi.beverage_order.pojo.ReturnOrderedProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class WxOrderServiceImpl implements WxOrderService {

    @Autowired
    ProductMapper productMapper;
    @Autowired
    OrderedProductMapper orderedProductMapper;
    @Autowired
    OrderListMapper orderListMapper;

    @Override
    public List<Product> getAllProduct() {
        System.out.println(productMapper.selectList(null));
        return productMapper.selectList(null);
    }

    @Override
    public Object getOrderedProduct(OrderedProduct orderedProduct) {
        orderedProductMapper.insert(orderedProduct);
        System.out.println("产品："+orderedProduct);
        return null;
    }

    @Override
    public ReturnOrderedProduct updateOrderedProduct(OrderedProduct orderedProduct) {
        orderedProductMapper.updateById(orderedProduct);
        ReturnOrderedProduct returnOrderedProduct = new ReturnOrderedProduct(orderedProduct.getId().toString(),orderedProduct.getOrderListId().toString(),orderedProduct.getProductId(),orderedProduct.getTemperature(),orderedProduct.getSweetness());
        return returnOrderedProduct;
    }

    @Override
    public Object buyThese(OrderList orderList) {
        OrderList purchased = orderListMapper.selectById(orderList.getId());
        purchased.setStarttime(new Timestamp(System.currentTimeMillis()));
        orderListMapper.updateById(purchased);
        return true;
    }

    @Override
    public Object deleteIt(OrderedProduct orderedProduct) {
        orderedProductMapper.deleteById(orderedProduct.getId());
        return null;
    }
}
